package com.wwwarehouse.usercenter.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.authoritydistribute.AuserRvBean;

import java.util.List;

/**
 * @author : mundane
 * @time : 2017/9/27 20:07
 * @description :
 * @file : AuserRvAdapter.java
 */
public class AuserRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

	private List<AuserRvBean> mDataList;

	public AuserRvAdapter(List<AuserRvBean> dataList) {
		this.mDataList = dataList;
	}

	@Override
	public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		if (viewType == 1) {
			View view1 = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_detail_auth_distribute, parent, false);
			return new AuserRvAdapterHolder1(view1);
		} else {
			View view0 = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_view0, parent, false);
			return new AuserRvAdapterHolder0(view0);
		}
	}

	@Override
	public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
		AuserRvBean auserRvBean = mDataList.get(position);
		if (holder instanceof AuserRvAdapterHolder0) {
            ((AuserRvAdapterHolder0) holder).mTvUserName.setText(auserRvBean.userName);
		} else {
			((AuserRvAdapterHolder1) holder).mTvAuthName.setText(auserRvBean.authName);
			((AuserRvAdapterHolder1) holder).mTvDetailMsg.setText(auserRvBean.detailMsg);

		}
	}

	@Override
	public int getItemCount() {
		return mDataList == null ? 0 : mDataList.size();
	}

	@Override
	public int getItemViewType(int position) {
		return mDataList.get(position).type;
	}

	class AuserRvAdapterHolder1 extends RecyclerView.ViewHolder {

		TextView mTvDetailMsg;
		TextView mTvAuthName;

		public AuserRvAdapterHolder1(View itemView) {
			super(itemView);
			mTvAuthName = (TextView) itemView.findViewById(R.id.tv_authName);
			mTvDetailMsg = (TextView) itemView.findViewById(R.id.tv_detail_msg);
		}
	}

	class AuserRvAdapterHolder0 extends RecyclerView.ViewHolder {

		TextView mTvUserName;

		public AuserRvAdapterHolder0(View itemView) {
			super(itemView);
			mTvUserName = (TextView) itemView.findViewById(R.id.tv_username);
		}
	}
}
